package com.zryc.shop.sms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.sms.entity.HomeNewProduct;
import com.zryc.shop.sms.service.IHomeNewProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 新鲜好物表 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api("新鲜好物管理接口")
@RequestMapping("/sms/home/newProduct")
public class HomeNewProductController {

    @Autowired
    private IHomeNewProductService homeNewProductService;

    @GetMapping("/list")
    @ApiOperation("分页查询")
    public Result list(@RequestParam(required = false) @ApiParam(value = "品牌名称关键词") String newProductName,
                       @RequestParam(required = false) @ApiParam(value = "推荐状态") Integer recommendStatus,
                       @RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "5") @ApiParam(value = "每页显示条数", required = true) Integer pageSize){
        return Result.ok(homeNewProductService.list(newProductName,recommendStatus,pageNum,pageSize));
    }

    @PostMapping("/create")
    @ApiOperation("选择新品推荐商品")
    public Result create(@RequestBody List<HomeNewProduct> homeNewproductList){
        return Result.ok(homeNewProductService.saveBatch(homeNewproductList));
    }
    @PostMapping("/update/recommendStatus")
    @ApiOperation("设置推荐/取消")
    public Result updateRecommendStatus(String ids, Integer recommendStatus){
        return Result.ok(homeNewProductService.updateRecommendStatus(ids,recommendStatus));
    }

    @PostMapping("/delete")
    @ApiOperation("删除新品推荐")
    public Result delete(String ids){
        String[] idList=ids.split(",");
        return Result.ok(homeNewProductService.removeBatchByIds(Arrays.asList(idList)));
    }

    @PostMapping("/update/sort/{id}")
    @ApiOperation("设置推荐排序值")
    public Result updateSort(@PathVariable Long id, @RequestParam Integer sort){
        return Result.ok(homeNewProductService.updateSort(id,sort));
    }


}
